<?php
header('Content-Type:text/html;charset=UTF-8');

include 'lib/checker.php';

@$img = $_FILES['img'];
@$name = $_REQUEST['name'];

$title = '添加联系人错误提示';
$jumpUrl = 'addperson.php';

if(empty($img['name'])){
	$message = '联系人的照片必须选定';
	include 'lib/headoff.php';
	die;
}

if($img['error']!=0){
	$mesage = '联系人的照片上传出错';
	include 'lib/headoff.php';
	die;
}

if(empty($name)){
	$message = '联系人的姓名必须填写';
	include 'lib/headoff.php';
	die;
}

$flag = move_uploaded_file($img['tmp_name'], 'imgs/'.$img['name']);
if(!$flag){
	$mesage = '联系人的照片上传失败';
	include 'lib/headoff.php';
	die;
}

require 'lib/db.php';
$flag = dbInsert('insert into person(name,imgUrl) values (:name,:imgUrl)',array('name'=>$name,'imgUrl'=>$img['name']));
if(!flag){
	$message = '添加联系人失败';
	include 'lib/headoff.php';
	die;
}

header('location:listperson.php');


